package com.haierp.event.inventory;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;

import com.haierp.model.Inventory;
import com.haierp.service.item.IOuterItemService;

public class SynInventoryListener implements ApplicationListener<SynInventoryEvent> {

	protected Logger logger = LogManager.getLogger(getClass());
	@Autowired
	private IOuterItemService outerItemService;

	@Override
	public void onApplicationEvent(SynInventoryEvent event) {
		Inventory[] inventory = event.getInventory();
		if (inventory != null) {
			for (int i = 0; i < inventory.length; i++) {
				try {
					outerItemService.synSkuInventory(inventory[i].getItemId(), inventory[i].getSkuId());
				} catch (Exception e) {
					logger.info("inventory syn error itemId:" + inventory[i].getItemId() + " skuId: "
							+ inventory[i].getSkuId(), e);
				}
			}
		}

	}

}
